<template>
  <el-container>
    <Header/>
    <el-main>
      <el-row :gutter="20">
        <el-col :span="22" :offset="1">
          <el-card>
            <div class="post-title">
              <img src="../../assets/logo.png" class="user-avator"/>
              <div class="user-info-cont">
                <p class="username">{{ record.authorName }}</p>
              </div>
              <div class="user-info-cont">
                <p class="title-text" align="right">{{ record.title }}</p>
              </div>
            </div>
            <div class="post-content">
              <p align="left">{{ record.content }}</p>
            </div>
            <el-row style="margin-top: 20px;margin-bottom: 0">
              <el-col :span="2">
                <el-tag type="info">帖子标签: </el-tag>
              </el-col>
              <el-col :span="3" v-for="tag in record.tagList" :key="tag.score">
                <el-tag> {{ tag.tag }} {{ tag.score }}</el-tag>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="22" :offset="1" style="margin-top: 20px">
          <el-card>
            <el-row>
              <el-col>
                <el-input
                  placeholder="请输入内容"
                  prefix-icon="el-icon-s-promotion"
                  v-model="commentForm.content"
                >
                  <el-button
                    style="padding-right:10px;font-size: large"
                    slot="suffix"
                    type="text"
                    size="medium"
                    @click="doComment"
                  >评论
                  </el-button
                  >
                </el-input>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="22" :offset="1" style="margin-top: 20px" v-for="comment in this.comments" :key="comment.cid">
          <el-card>
            <el-row>
              <el-col>
                {{ comment.uid}} : {{ comment.content }}
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <el-row>
      </el-row>
    </el-main>
    <el-footer></el-footer>
  </el-container>
</template>

<script>
import Header from '../../components/header'

export default {
  name: 'postBody',
  components: {
    Header
  },
  data () {
    return {
      record: '',
      comments: [],
      commentForm: {
        pid: '',
        uid: '',
        content: '',
        precursor: ''
      }
    }
  },
  mounted () {
    this.getData()
  },
  methods: {
    clickTest () {
      console.log(this.comments)
    },
    getData () {
      this.$axios.get('/post/queryByPid?pid=' + this.$route.query.pid).then(res => {
        this.record = res.data.data
        this.commentForm.precursor = this.$route.query.pid
        this.commentForm.pid = this.$route.query.pid
        this.commentForm.uid = this.$store.getters.getUser.UID
        this.$axios.get('/queryComment?pid=' + this.$route.query.pid).then(res2 => {
          this.comments = res2.data.data
          console.log('************')
          console.log('************')
          console.log(res2.data.data)
        })
      })
      console.log(this.comments)
    },
    doComment () {
      if (this.commentForm.content === '' || this.commentForm.content === undefined) {
        this.$message({
          message: '评论不能为空',
          type: 'error'
        })
      }
      this.$axios.post('/comment', this.commentForm).then(res => {
        console.log(this.commentForm)
        this.getData()
        this.$message({
          message: '评论成功',
          type: 'success'
        })
      })
    }
  }
}
</script>

<style scoped>
.el-main {
  background-color: #f4f9ff;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-row-inline {
  display: flex;
  flex-wrap: wrap;
}
html, body, #app, .el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}

.text {
  font-size: 20px;
}

.item {
  padding: 8px 0;
  height: 50px;
  font-size: larger;
}

.box-card {
  height: 600px;
  margin-left: 20px;
  margin-top: 50px;
}
.username {
  font-size: x-large;
  font-family: "Apple SD Gothic Neo",serif;
  margin-left: 0px;
  width: 100px;
}
el-row{
  display: flex;
}
.box-card1 {
  margin-left: 80px;
}

.box-card2 {
  margin-right: 20%;
}
.user-avator {
  height: 50px;
}
.el-menu-item {
  font-size: larger;

}
.post-card {
  margin-left: 80px;
  height: 240px;
  margin-top: 10px;
}

.post-title {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
  height: 30px;
}
.post-content {
  line-height:2;
  background-color:#dde9f6;
  white-space: pre-line;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  align-items: center;
  display: flex;
}
.post-footer {
  line-height:2;
  color: #999;
}
.title-text {
  display: flex;
  padding-bottom: 20px;
  margin-bottom: 20px;
  font-size: xx-large;
}
.el-post-title {
  font-size: larger;
  font-family: "Apple Color Emoji",serif;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
  margin-top: 0;
}
.el-row {
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap
}

.el-card {
  min-width: 100%;
  transition: all .5s;
}
.el-col{
  display: flex;
  flex-wrap: wrap;
}
.el-row-inline {
  display: flex;
  flex-wrap: wrap;
}
</style>
